﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SeaBattle.UI.Web.Models;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.UI.Web.Controllers
{
    public class GameController : Controller
    {
        private IGameRepository gameRepository;
        private IPlayerService playerService;

        public GameController(IGameRepository gameRepository, IPlayerService playerService)
        {
            this.gameRepository = gameRepository;
            this.playerService = playerService;
        }

        public ActionResult Index(int id)
        {
            var game = gameRepository.GetGame(id);
            var me = playerService.GetPlayer(User.Identity.Name);
            if (game.Opponent == null)
            {
                game.JoinOpponent(me);
            }
            
            return View(new GameViewModel { Game = game });
        }

        [ChildActionOnly]

        public ActionResult GameBoard()
        {
            return View("ChildActions/GameBoard");
        }
    }
}
